package com.liip.app.controller;


import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.liip.app.common.CustException;
import com.liip.app.common.R;

/**
 * 前端控制器,统一返回结果
 * @Auther: luolin
 * @Date: 2020-10-15 4:06 PM
 * @Description:
 */
@RestController
@RequestMapping("/job")
public class JobController {
	
	@GetMapping("findAll")
	public R findAll() {
		List<String> list = new ArrayList<String>();
		list.add("aaa");
		list.add("bbb");
		list.add("ccc");
		list.add("ddd");
		return R.ok().data("items", list);
	}
	
	@DeleteMapping("{id}")
	public R removeUer(@PathVariable String id) {
		
		boolean flag = false;
		if(flag) {
			return R.ok();
		}else {
			return R.error();
		}
	}
	
	@PostMapping("{id}")
	public R exception(@PathVariable Integer id) {
		int i = 10/id;
		return R.ok().message("执行结果为："+i);
	}
	
	@PostMapping("cust")
	public R exception() {
		try {
			int i = 10/0;
		}catch(Exception e){
			throw new CustException(20001,"执行自定义异常处理.....");
		}
		return R.ok();
	}
}

